package com.leaf.grayrotate;


import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {
	
	private MainSurfaceView m_mainsurfaceview;
	private DialogInterface.OnClickListener m_dialoginterface;
	private AlertDialog.Builder m_dialog_builder;
	private AlertDialog m_dialog_exit;
	
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		
		
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        m_mainsurfaceview = new MainSurfaceView(this);       
		setContentView(m_mainsurfaceview);
		m_dialoginterface = new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				if(which == DialogInterface.BUTTON_POSITIVE)
					m_mainsurfaceview.GameExit();
         	   	MainActivity.this.finish();
			}
		};
		m_dialog_builder = new AlertDialog.Builder(this);
		m_dialog_builder.setCancelable(true);
		m_dialog_builder.setMessage(R.string.alert_exit_title_text);
		m_dialog_builder.setPositiveButton(R.string.alert_exit_confirm_button_text, m_dialoginterface);
		m_dialog_builder.setNegativeButton(R.string.alert_exit_cancel_button_text, m_dialoginterface);
		m_dialog_exit = m_dialog_builder.create();
		
	}
	
	@Override
	public void onStart(){
		super.onStart();    
	}
	
	@Override
	public void onStop(){
		super.onStop();
	}
	
	@Override
	public void onDestroy(){
		super.onDestroy();
	}
	
	@Override
	public void onBackPressed(){
		//Simple way
		m_mainsurfaceview.GameExit();
 	   	MainActivity.this.finish();
		//New method
//		m_dialog_exit.show();
		/*
		//Old method
		new AlertDialog.Builder(this)
           .setMessage("Are you sure you want to exit game ?")
           .setCancelable(false)
           .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int id) {
            	   m_mainsurfaceview.GameExit();
            	   MainActivity.this.finish();
               }
           })
           .setNegativeButton("No", null)
           .show();
         */
	}
}
